{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Extractive"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div class=\"alert alert-info\">\n",
    "\n",
    "This tutorial is available as an IPython notebook at [Malaya/example/qa-extractive](https://github.com/huseinzol05/Malaya/tree/master/example/qa-extractive).\n",
    "    \n",
    "</div>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div class=\"alert alert-warning\">\n",
    "\n",
    "This module only trained on standard language structure, so it is not save to use it for local language structure.\n",
    "    \n",
    "</div>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "\n",
    "os.environ['CUDA_VISIBLE_DEVICES'] = ''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import logging\n",
    "\n",
    "logging.basicConfig(level=logging.INFO)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/husein/.local/lib/python3.8/site-packages/bitsandbytes/cextension.py:34: UserWarning: The installed version of bitsandbytes was compiled without GPU support. 8-bit optimizers, 8-bit multiplication, and GPU quantization are unavailable.\n",
      "  warn(\"The installed version of bitsandbytes was compiled without GPU support. \"\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/home/husein/.local/lib/python3.8/site-packages/bitsandbytes/libbitsandbytes_cpu.so: undefined symbol: cadam32bit_grad_fp32\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:torch.distributed.nn.jit.instantiator:Created a temporary directory at /tmp/tmpmzsrez5d\n",
      "INFO:torch.distributed.nn.jit.instantiator:Writing /tmp/tmpmzsrez5d/_remote_module_non_scriptable.py\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 2.72 s, sys: 4 s, total: 6.72 s\n",
      "Wall time: 1.94 s\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/husein/dev/malaya/malaya/tokenizer.py:214: FutureWarning: Possible nested set at position 3397\n",
      "  self.tok = re.compile(r'({})'.format('|'.join(pipeline)))\n",
      "/home/husein/dev/malaya/malaya/tokenizer.py:214: FutureWarning: Possible nested set at position 3927\n",
      "  self.tok = re.compile(r'({})'.format('|'.join(pipeline)))\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "\n",
    "import malaya\n",
    "from pprint import pprint"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### What is Extractive QA\n",
    "\n",
    "is a reading comprehension problem, eg,\n",
    "\n",
    "```json\n",
    "{\n",
    "    'title': 'Normans',\n",
    "    'paragraphs': [\n",
    "        {\n",
    "            'context': 'Orang Norman (Norman: Nourmands; Perancis: Normands; Latin: Normanni) ialah orang-orang yang pada abad ke-10 dan ke-11 memberikan nama mereka kepada Normandy, sebuah wilayah di Perancis. Mereka diturunkan daripada Norse (\"Norman\" berasal daripada penyerang \"Norseman\") dan lanun dari Denmark, Iceland dan Norway yang, di bawah pimpinan mereka Rollo, bersetuju untuk bersumpah fealty kepada Raja Charles III dari Francia Barat. Melalui generasi asimilasi dan percampuran dengan penduduk asli Frankish dan Roman-Gaulish, keturunan mereka akan beransur-ansur bergabung dengan budaya Carolingian yang berpusat di Francia Barat. Identiti budaya dan etnik yang berbeza dari orang Norman muncul pada mulanya pada separuh pertama abad ke-10, dan ia terus berkembang pada abad-abad yang berjaya.',\n",
    "            'qas': [\n",
    "                {\n",
    "                    'question': 'Di negara manakah Normandy berada?',\n",
    "                    'answers': [\n",
    "                        {'text': 'Perancis', 'answer_start': 177},\n",
    "                        {'text': 'Perancis', 'answer_start': 177},\n",
    "                        {'text': 'Perancis', 'answer_start': 177},\n",
    "                        {'text': 'Perancis', 'answer_start': 177},\n",
    "                    ],\n",
    "                    'id': '56ddde6b9a695914005b9628',\n",
    "                    'is_impossible': False,\n",
    "                }\n",
    "            ],\n",
    "        }\n",
    "    ],\n",
    "}\n",
    "```\n",
    "\n",
    "So we need to give a long paragraph and multiple questions, and the model will return answers based on that paragraph with start and end spans. Read more about SQUAD dataset https://rajpurkar.github.io/SQuAD-explorer/"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### List available HuggingFace models"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'mesolitica/finetune-qa-t5-tiny-standard-bahasa-cased': {'Size (MB)': 139,\n",
       "  'exact-ms': 0.426955861,\n",
       "  'f1-ms': 0.5113033923,\n",
       "  'exact-en': 0.4692567567,\n",
       "  'f1-en': 0.541063384},\n",
       " 'mesolitica/finetune-qa-t5-small-standard-bahasa-cased': {'Size (MB)': 242,\n",
       "  'exact-ms': 0.530340113,\n",
       "  'f1-ms': 0.61693299,\n",
       "  'exact-en': 0.55878378,\n",
       "  'f1-en': 0.6292999233},\n",
       " 'mesolitica/finetune-qa-t5-base-standard-bahasa-cased': {'Size (MB)': 892,\n",
       "  'exact-ms': 0.570354729,\n",
       "  'f1-ms': 0.64136968,\n",
       "  'exact-en': 0.570354729,\n",
       "  'f1-en': 0.64136968144}}"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "malaya.qa.extractive.available_huggingface"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Load HuggingFace model\n",
    "\n",
    "```python\n",
    "def huggingface(\n",
    "    model: str = 'mesolitica/finetune-qa-t5-small-standard-bahasa-cased',\n",
    "    force_check: bool = True,\n",
    "    **kwargs,\n",
    "):\n",
    "    \"\"\"\n",
    "    Load HuggingFace model to answer extractive question answers.\n",
    "\n",
    "    Parameters\n",
    "    ----------\n",
    "    model: str, optional (default='mesolitica/finetune-qa-t5-small-standard-bahasa-cased')\n",
    "        Check available models at `malaya.qa.extractive.available_huggingface`.\n",
    "    force_check: bool, optional (default=True)\n",
    "        Force check model one of malaya model.\n",
    "        Set to False if you have your own huggingface model.\n",
    "\n",
    "    Returns\n",
    "    -------\n",
    "    result: malaya.torch_model.huggingface.ExtractiveQA\n",
    "    \"\"\"\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "model = malaya.qa.extractive.huggingface(model = 'mesolitica/finetune-qa-t5-small-standard-bahasa-cased')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Copy from wikipedia and news"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "# https://ms.wikipedia.org/wiki/Mohd_Najib_bin_Abdul_Razak\n",
    "\n",
    "p_wikipedia = \"\"\"\n",
    "Najib razak telah dipilih untuk Parlimen Malaysia pada tahun 1976, \n",
    "pada usia 23 tahun, menggantikan bapanya duduk di kerusi Pekan yang berpangkalan di Pahang. \n",
    "Dari tahun 1982 hingga 1986 beliau menjadi Menteri Besar (Ketua Menteri) Pahang, \n",
    "sebelum memasuki persekutuan Kabinet Tun Dr Mahathir Mohamad pada tahun 1986 sebagai Menteri Kebudayaan, Belia dan Sukan. \n",
    "Beliau telah berkhidmat dalam pelbagai jawatan Kabinet sepanjang baki tahun 1980-an dan 1990-an, termasuk sebagai Menteri Pertahanan dan Menteri Pelajaran. \n",
    "Beliau menjadi Timbalan Perdana Menteri pada 7 Januari 2004, berkhidmat di bawah Perdana Menteri Tun Dato' Seri Abdullah Ahmad Badawi, \n",
    "sebelum menggantikan Badawi setahun selepas Barisan Nasional mengalami kerugian besar dalam pilihan raya 2008. \n",
    "Di bawah kepimpinan beliau, Barisan Nasional memenangi pilihan raya 2013, \n",
    "walaupun buat kali pertama dalam sejarah Malaysia pembangkang memenangi majoriti undi popular.\n",
    "\"\"\"\n",
    "q_wikipedia = [\n",
    "    'pada umur berapa najib razak menggantikan ayahnya', \n",
    "    'Apakah jawatan yang pernah dipegang oleh Najib Razak',\n",
    "    'what date najib become deputy prime minister',\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "# https://www.malaysiakini.com/news/574914\n",
    "\n",
    "p_news = \"\"\"\n",
    "Bekas perdana menteri Najib Razak mempersoalkan tindakan polis yang menurutnya tidak serta-merta mengeluarkan kenyataan berhubung dakwaan Adun Perikatan Nasional (PN) \"merancang\" insiden rogol.\n",
    "Sedangkan, kata ahli parlimen Pekan itu, polis pantas mengeluarkan kenyataan apabila dia dilapor terlupa mengimbas MySejahtera sebelum masuk restoran.\n",
    "\"Berita Najib lupa scan MySejahtera tular, kenyataan polis terus keluar. Berita Dr Mahathir Mohamad lupa scan, kenyataan, polis serta-merta keluar.\n",
    "\"Sebab itu saya pelik kenapa pihak polis belum sempat keluar apa-apa kenyataan berhubung kes seorang gadis membuat laporan polis untuk dakwa Adun PN rancang insiden rogolnya,\" katanya di Facebook hari ini.\n",
    "Najib merujuk dakwaan seorang wanita yang mendakwa dirogol kenalan kepada Adun Gombak Setia, Hilman Idham.\n",
    "Wanita itu mendakwa ahli politik dari Bersatu berkenaan merancang insiden yang berlaku pada 5 Dis lalu.\n",
    "Menurut laporan polis pada 8 Mei, mangsa mendakwa kejadian itu berlaku di sebuah hotel di Selangor, yang pada masa itu berada di bawah perintah kawalan pergerakan bersyarat (PKPB).\n",
    "\"\"\"\n",
    "\n",
    "q_news = [\n",
    "    'siapakah yang mempersoalkan tindakan polis', \n",
    "    'siapakah Adun Gombak Setia',\n",
    "    'when does make the allegation',\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "# https://www.parlimen.gov.my/files/hindex/pdf/DR-19122022.pdf\n",
    "\n",
    "p_parlimen = \"\"\"\n",
    "Menteri Dalam Negeri [Datuk Seri Saifuddin Nasution bin Ismail]:\n",
    "Assalamualaikum warahmatullahi wabarakatuh. Tuan Yang diPertua, saya mohon\n",
    "mencadangkan:\n",
    "“Bahawa Majlis ini memerintahkan Ketua Polis Negara\n",
    "menjaga supaya selama Penggal Dewan Rakyat Parlimen Kelima\n",
    "Belas yang ada sekarang, jalan-jalan melalui lorong-lorong menuju ke\n",
    "Dewan ini hendaklah sentiasa terbuka dan boleh dilalui dan jangan\n",
    "ada apa-apa halangan menghalang Ahli-ahli hendak pergi dan balik\n",
    "dari Dewan ini, jangan berlaku apa-apa kacau bilau di jalan-jalan\n",
    "menuju ke Dewan ini, dan supaya jangan ada huru-hara di Bangunan\n",
    "Dewan ini dan berhampiran dengan bangunan ini; dan Setiausaha\n",
    "Dewan Rakyat hendaklah menyampaikan perintah ini kepada Ketua\n",
    "Polis Negara yang tersebut itu”.\n",
    "Terima kasih.\n",
    "Timbalan Menteri Dalam Negeri [Datuk Seri Dr. Shamsul Anuar bin\n",
    "Nasarah]: Tuan Yang di-Pertua, saya mohon menyokong.\n",
    "Tuan Yang di-Pertua: Terima kasih. Ahli-ahli Yang Berhormat, masalahnya\n",
    "ialah usul oleh Yang Berhormat Menteri Dalam Negeri yang telah dibacakan tadi\n",
    "hendaklah dipersetujukan\n",
    "\"\"\"\n",
    "\n",
    "q_parlimen = [\n",
    "    'siapakah yang mempersoalkan tindakan polis', \n",
    "    'apakah ketua polis negara yang perlukan dibuat',\n",
    "    'who need to instruct chief police',\n",
    "]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Predict\n",
    "\n",
    "```python\n",
    "def predict(\n",
    "    self,\n",
    "    paragraph_text: str,\n",
    "    question_texts: List[str],\n",
    "    validate_answers: bool = True,\n",
    "    validate_questions: bool = False,\n",
    "    minimum_threshold_question: float = 0.05,\n",
    "    **kwargs,\n",
    "):\n",
    "    \"\"\"\n",
    "    Predict extractive answers from questions given a paragraph.\n",
    "\n",
    "    Parameters\n",
    "    ----------\n",
    "    paragraph_text: str\n",
    "    question_texts: List[str]\n",
    "        List of questions, results really depends on case sensitive questions.\n",
    "    validate_answers: bool, optional (default=True)\n",
    "        if True, will check the answer is inside the paragraph.\n",
    "    validate_questions: bool, optional (default=True)\n",
    "        if True, validate the question is subset of the paragraph using `sklearn.feature_extraction.text.CountVectorizer`\n",
    "    minimum_threshold_question: float, optional (default=0.05)\n",
    "        minimum score from `cosine_similarity`, only useful if `validate_questions = True`.\n",
    "    **kwargs: vector arguments pass to huggingface `generate` method.\n",
    "        Read more at https://huggingface.co/docs/transformers/main_classes/text_generation\n",
    "\n",
    "    Returns\n",
    "    -------\n",
    "    result: List[str]\n",
    "    \"\"\"\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/husein/.local/lib/python3.8/site-packages/transformers/generation/utils.py:1260: UserWarning: Using the model-agnostic default `max_length` (=20) to control the generation length. We recommend setting `max_new_tokens` to control the maximum length of the generation.\n",
      "  warnings.warn(\n",
      "spaces_between_special_tokens is deprecated and will be removed in transformers v5. It was adding spaces between `added_tokens`, not special tokens, and does not exist in our fast implementation. Future tokenizers will handle the decoding process on a per-model rule.\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "['23 tahun', 'Menteri Besar (Ketua Menteri) Pahang', '7 Januari 2004']"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.predict(p_wikipedia, q_wikipedia)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Najib Razak', 'Adun Gombak Setia, Hilman Idham', '5 Dis lalu']"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.predict(p_news, q_news)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Datuk Seri Saifuddin Nasution bin Ismail',\n",
       " '\"Bahawa Majlis ini memerintahkan Ketua Polis Negara menjaga supaya selama Penggal Dewan Rakyat Parlimen Kelima Belas',\n",
       " 'Datuk Seri Saifuddin Nasution bin Ismail']"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.predict(p_parlimen, q_parlimen, max_length=50, \n",
    "    num_beams=5, \n",
    "    early_stopping=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Able to mixed MS and EN\n",
    "\n",
    "Paragraph or questions can be both MS or EN or mixed."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "# https://ms.wikipedia.org/wiki/Mohd_Najib_bin_Abdul_Razak\n",
    "\n",
    "p_wikipedia = \"\"\"\n",
    "Najib razak telah dipilih untuk Parlimen Malaysia pada tahun 1976, \n",
    "pada usia 23 tahun, menggantikan bapanya duduk di kerusi Pekan yang berpangkalan di Pahang. \n",
    "Dari tahun 1982 hingga 1986 beliau menjadi Menteri Besar (Ketua Menteri) Pahang, \n",
    "sebelum memasuki persekutuan Kabinet Tun Dr Mahathir Mohamad pada tahun 1986 sebagai Menteri Kebudayaan, Belia dan Sukan. \n",
    "Beliau telah berkhidmat dalam pelbagai jawatan Kabinet sepanjang baki tahun 1980-an dan 1990-an, termasuk sebagai Menteri Pertahanan dan Menteri Pelajaran. \n",
    "Beliau menjadi Timbalan Perdana Menteri pada 7 Januari 2004, berkhidmat di bawah Perdana Menteri Tun Dato' Seri Abdullah Ahmad Badawi, \n",
    "sebelum menggantikan Badawi setahun selepas Barisan Nasional mengalami kerugian besar dalam pilihan raya 2008. \n",
    "Di bawah kepimpinan beliau, Barisan Nasional memenangi pilihan raya 2013, \n",
    "walaupun buat kali pertama dalam sejarah Malaysia pembangkang memenangi majoriti undi popular.\n",
    "\"\"\"\n",
    "q_wikipedia = [\n",
    "    'pada umur berapa najib razak menggantikan ayahnya', \n",
    "    'Apakah jawatan yang pernah dipegang oleh Najib Razak',\n",
    "    'what age najib razak replaced his father']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['23 tahun', 'Menteri Besar (Ketua Menteri) Pahang', '23 tahun']"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.predict(p_wikipedia, q_wikipedia)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "# https://www.malaysiakini.com/news/574914\n",
    "\n",
    "p_news = \"\"\"\n",
    "Bekas perdana menteri Najib Razak mempersoalkan tindakan polis yang menurutnya tidak serta-merta mengeluarkan kenyataan berhubung dakwaan Adun Perikatan Nasional (PN) \"merancang\" insiden rogol.\n",
    "Sedangkan, kata ahli parlimen Pekan itu, polis pantas mengeluarkan kenyataan apabila dia dilapor terlupa mengimbas MySejahtera sebelum masuk restoran.\n",
    "\"Berita Najib lupa scan MySejahtera tular, kenyataan polis terus keluar. Berita Dr Mahathir Mohamad lupa scan, kenyataan, polis serta-merta keluar.\n",
    "\"Sebab itu saya pelik kenapa pihak polis belum sempat keluar apa-apa kenyataan berhubung kes seorang gadis membuat laporan polis untuk dakwa Adun PN rancang insiden rogolnya,\" katanya di Facebook hari ini.\n",
    "Najib merujuk dakwaan seorang wanita yang mendakwa dirogol kenalan kepada Adun Gombak Setia, Hilman Idham.\n",
    "Wanita itu mendakwa ahli politik dari Bersatu berkenaan merancang insiden yang berlaku pada 5 Dis lalu.\n",
    "Menurut laporan polis pada 8 Mei, mangsa mendakwa kejadian itu berlaku di sebuah hotel di Selangor, yang pada masa itu berada di bawah perintah kawalan pergerakan bersyarat (PKPB).\n",
    "\"\"\"\n",
    "\n",
    "q_news = [\n",
    "    'siapakah yang mempersoalkan tindakan polis', \n",
    "    'siapakah Adun Gombak Setia',\n",
    "    'who is the victim on 8 may incident',\n",
    "    'where does the 8 may incident happened',\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Najib Razak',\n",
       " 'Adun Gombak Setia, Hilman Idham',\n",
       " 'Adun Gombak Setia, Hilman Idham',\n",
       " 'sebuah hotel di Selangor']"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.predict(p_news, q_news)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "# https://en.wikipedia.org/wiki/Anwar_Ibrahim\n",
    "\n",
    "p_anwar = \"\"\"\n",
    "A graduate from University of Malaya, Anwar started his political career as one of the founders of youth organisation Angkatan Belia Islam Malaysia (ABIM).[4] After joining the United Malays National Organisation (UMNO), the major party in the long-time ruling BN coalition, Anwar held several cabinet positions in successive governments in the 1980s and 1990s. He was Deputy Prime Minister and Finance Minister during the 1990s and was prominent in Malaysia's response to the 1997 Asian financial crisis.[5] In 1998, he was removed from all posts by Prime Minister Mahathir Mohamad and went on to spearhead the Reformasi movement against the government. Anwar was jailed in April 1999 after a trial for sodomy and corruption that was criticised by human rights groups[6] and several foreign governments, until his release in 2004 after his conviction was overturned. He made a comeback as Leader of the Opposition from 2008 to 2015 and coalesced opposition parties into the Pakatan Rakyat (PR) coalition, which unsuccessfully contested in the 2008 and 2013 general elections. He disputed the results of the 2013 elections and led a protest in response.\n",
    "\n",
    "In 2014, Anwar's attempt to become Selangor head of government in the 2014 Kajang Move led to a nine-month political crisis, which ended when he was sentenced to another five years imprisonment after a second sodomy conviction in 2015.[7] While still in prison, Anwar re-joined Mahathir Mohamad in the new Pakatan Harapan (PH) coalition in absentia, which went on to win the 2018 general election. Mahathir outlined a plan for Anwar to take over from himself as Prime Minister after an unspecified interim period.[8] Anwar received a royal pardon from Yang di-Pertuan Agong Muhammad V[9] and was released from prison in May 2018.[10][11] He returned to parliament in the 2018 Port Dickson by-election while his wife Wan Azizah Wan Ismail served as the Deputy Prime Minister in the PH administration. The collapse of the coalition during 2020–22 Malaysian political crisis led to the new Perikatan Nasional (PN) coalition under Muhyiddin Yassin being sworn in and Anwar becoming Leader of the Opposition for the second time in May 2020.\n",
    "\"\"\"\n",
    "\n",
    "q_anwar = [\n",
    "    'tahun bila kajang move', \n",
    "    'macam mana anwar mula his political career',\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['1998', 'youth organisation Angkatan Belia Islam Malaysia (ABIM).']"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.predict(p_anwar, q_anwar)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.10"
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
